<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "order_item".
 *
 * @property int $id
 * @property int $order_id
 * @property string|null $item_sort
 * @property string $increment_id
 * @property string $item_type
 * @property string $item_status
 * @property int $product_id
 * @property string $spu
 * @property string $sku
 * @property string $gender 尺码类型
 * @property string $brand 产品的品牌
 * @property int $product_is_clean 下单时，产品是否清仓
 * @property int $factory_id 派单去哪个工厂生产
 * @property float $price 加入购物车价格，但是还没有计算优惠金额
 * @property int $qty_ordered 下单数量
 * @property int $qty_delivery 请求验收数量
 * @property int $qty_passed 验收通过数量
 * @property int $created_at
 * @property int $updated_at
 * @property string $attr 订单定制属性
 * @property string $attr2 订单定制属性
 * @property string $additional_data 定制属性，来自Magneto。ERP解析之前的原始数据
 * @property string $stock_code_key 库存标识分类
 * @property string $stock_code 库存标识
 * @property string $size_original 网站选择的尺码
 * @property int $has_engravings 是否刻字
 * @property string $metal_color 金属材质，10k，14k
 * @property int $stone_type 是否含有莫桑石
 * @property int $changed item换货次数
 * @property string $factory_change_confirmed_status 变更确认，发货时要检查这个状态值是否为可发货状态
 * @property string $last_item_info 修改了刻字、尺码、定制属性后，保存修改前的数据，工厂确认变更时可以参考
 * @property string $distributor 分销单
 * @property int $distributor_item_id Gnoce存储Jeulia分销单的Item.id
 * @property float $base_price 加入购物车价格，但是还没有计算优惠金额（美元）
 * @property int $item_approved item是否扣减库存的标识
 * @property float $original_price 划线价格
 * @property float $base_original_price 划线价格（美元）
 * @property float $discount_amount 优惠券抵扣的金额
 * @property float $base_discount_amount 优惠券抵扣的金额（美元）
 * @property float $row_total price * qty_ordered
 * @property float $base_row_total price * qty_ordered（美元）
 * @property float $special_price 别用此值
 * @property float $size_price 个别尺码加的费用，已经算在price里
 * @property float $engrave_price 刻字加的费用，已经算在price里
 * @property int $repair 换货时选择的指定category_id，则标记为repair，考核工厂用
 * @property string $applied_rule_ids 来自Magento，还没发现什么地方用
 * @property int $is_free 标记产品是否免费
 * @property string $google_lineItemId googleExpress里的item.id，通知googleExpress发货等接口时用
 * @property int $has_rejects 1：次品，0：正常
 * @property int $item_export 定制照片款：是否导出
 * @property string $extra 3D是否导出
 * @property string|null $engravings
 * @property int $is_valuable 是否k金和莫桑石
 * @property string|null $product_set_number 套装编码
 */
class Orderitem extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'order_item';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['order_id', 'product_id', 'product_is_clean', 'factory_id', 'qty_ordered', 'qty_delivery', 'qty_passed', 'created_at', 'updated_at', 'has_engravings', 'stone_type', 'changed', 'distributor_item_id', 'item_approved', 'repair', 'is_free', 'has_rejects', 'item_export', 'is_valuable'], 'integer'],
            [['increment_id', 'factory_id', 'attr', 'attr2', 'additional_data', 'metal_color', 'last_item_info', 'applied_rule_ids', 'google_lineItemId', 'extra'], 'required'],
            [['item_type', 'item_status', 'gender', 'attr', 'attr2', 'additional_data', 'factory_change_confirmed_status', 'last_item_info', 'applied_rule_ids'], 'string'],
            [['price', 'base_price', 'original_price', 'base_original_price', 'discount_amount', 'base_discount_amount', 'row_total', 'base_row_total', 'special_price', 'size_price', 'engrave_price'], 'number'],
            [['item_sort', 'increment_id', 'brand', 'extra', 'product_set_number'], 'string', 'max' => 50],
            [['spu', 'sku', 'stock_code_key', 'stock_code'], 'string', 'max' => 60],
            [['size_original', 'metal_color', 'google_lineItemId'], 'string', 'max' => 100],
            [['distributor'], 'string', 'max' => 20],
            [['engravings'], 'string', 'max' => 80],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'order_id' => Yii::t('app', 'Order ID'),
            'item_sort' => Yii::t('app', 'Item Sort'),
            'increment_id' => Yii::t('app', 'Increment ID'),
            'item_type' => Yii::t('app', 'Item Type'),
            'item_status' => Yii::t('app', 'Item Status'),
            'product_id' => Yii::t('app', 'Product ID'),
            'spu' => Yii::t('app', 'Spu'),
            'sku' => Yii::t('app', 'Sku'),
            'gender' => Yii::t('app', 'Gender'),
            'brand' => Yii::t('app', 'Brand'),
            'product_is_clean' => Yii::t('app', 'Product Is Clean'),
            'factory_id' => Yii::t('app', 'Factory ID'),
            'price' => Yii::t('app', 'Price'),
            'qty_ordered' => Yii::t('app', 'Qty Ordered'),
            'qty_delivery' => Yii::t('app', 'Qty Delivery'),
            'qty_passed' => Yii::t('app', 'Qty Passed'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'attr' => Yii::t('app', 'Attr'),
            'attr2' => Yii::t('app', 'Attr2'),
            'additional_data' => Yii::t('app', 'Additional Data'),
            'stock_code_key' => Yii::t('app', 'Stock Code Key'),
            'stock_code' => Yii::t('app', 'Stock Code'),
            'size_original' => Yii::t('app', 'Size Original'),
            'has_engravings' => Yii::t('app', 'Has Engravings'),
            'metal_color' => Yii::t('app', 'Metal Color'),
            'stone_type' => Yii::t('app', 'Stone Type'),
            'changed' => Yii::t('app', 'Changed'),
            'factory_change_confirmed_status' => Yii::t('app', 'Factory Change Confirmed Status'),
            'last_item_info' => Yii::t('app', 'Last Item Info'),
            'distributor' => Yii::t('app', 'Distributor'),
            'distributor_item_id' => Yii::t('app', 'Distributor Item ID'),
            'base_price' => Yii::t('app', 'Base Price'),
            'item_approved' => Yii::t('app', 'Item Approved'),
            'original_price' => Yii::t('app', 'Original Price'),
            'base_original_price' => Yii::t('app', 'Base Original Price'),
            'discount_amount' => Yii::t('app', 'Discount Amount'),
            'base_discount_amount' => Yii::t('app', 'Base Discount Amount'),
            'row_total' => Yii::t('app', 'Row Total'),
            'base_row_total' => Yii::t('app', 'Base Row Total'),
            'special_price' => Yii::t('app', 'Special Price'),
            'size_price' => Yii::t('app', 'Size Price'),
            'engrave_price' => Yii::t('app', 'Engrave Price'),
            'repair' => Yii::t('app', 'Repair'),
            'applied_rule_ids' => Yii::t('app', 'Applied Rule Ids'),
            'is_free' => Yii::t('app', 'Is Free'),
            'google_lineItemId' => Yii::t('app', 'Google Line Item ID'),
            'has_rejects' => Yii::t('app', 'Has Rejects'),
            'item_export' => Yii::t('app', 'Item Export'),
            'extra' => Yii::t('app', 'Extra'),
            'engravings' => Yii::t('app', 'Engravings'),
            'is_valuable' => Yii::t('app', 'Is Valuable'),
            'product_set_number' => Yii::t('app', 'Product Set Number'),
        ];
    }

    /**
     * Notes: 获取到order订单
     * User: Administrator
     * DateTime: 2021/4/26 16:11
     * @return \yii\db\ActiveQuery
     */
    public function getOrder()
    {
        return $this->hasOne(Order::class, ['id' => 'order_id']);
    }


    /**
     * Notes: 获取产品id
     * User: Administrator
     * DateTime: 2021/4/26 16:38
     * @return \yii\db\ActiveQuery
     */
    public function getProduct()
    {
        return $this->hasOne(Product::class, ['id'=>'product_id']);
    }
}
